package com.idanchuang.component.businesslog.es.annotations;

import org.elasticsearch.index.VersionType;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * <p>
 * Identifies a domain object to be persisted to Elasticsearch.
 * </p>
 *
 * @author jiang
 * @date 2019-11-25 11:33
 */
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface Document {

    /**
     * Name of the Elasticsearch index.
     * <ul>
     * <li>Lowercase only</li>
     * <li><Cannot include \, /, *, ?, ", <, >, |, ` ` (space character), ,, #/li>
     * <li>Cannot start with -, _, +</li>
     * <li>Cannot be . or ..</li>
     * <li>Cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit
     * faster)</li>
     * </ul>
     */
    String indexName();

    /**
     * Mapping type name.
     */
    String type() default "_doc";

    /** 索引生命周期-滚动模式, 默认按天滚动 */
    RollMode rollMode() default RollMode.DAY;

    /** 文档保留天数, 默认0为永久 */
    int maxDays() default 0;

    /**
     * Use server-side settings when creating the index.
     */
    boolean useServerConfiguration() default false;

    /**
     * Number of shards for the index {@link #indexName()}. Used for index creation.
     */
    short shards() default 5;

    /**
     * Number of replicas for the index {@link #indexName()}. Used for index creation.
     */
    short replicas() default 1;

    /**
     * Refresh interval for the index {@link #indexName()}. Used for index creation.
     */
    String refreshInterval() default "1s";

    /**
     * Index storage type for the index {@link #indexName()}. Used for index creation.
     */
    String indexStoreType() default "fs";

    /**
     * Configuration whether to create an index on repository bootstrapping.
     */
    boolean createIndex() default true;

    /**
     * Configuration of version management.
     */
    VersionType versionType() default VersionType.EXTERNAL;
}

